/trunk/Qlab 0.1/Qlab/ParserCore/Tools/gplex-distro-1.1.4/project/SpecFiles/gplex.y

# · Happy · 287 lines · 247 code · 40 blank · 0 comment · 0 complexity · a304f53d89ee6bb461181bf56f4e6828 MD5 · raw file

  1. /*
  2. * Parser spec for GPLEX
  3. * Process with > GPPG /gplex /no-lines gplex.y
  4. */
  5. %using System.Collections
  6. %namespace QUT.Gplex.Parser
  7. %YYLTYPE LexSpan
  8. %partial
  9. %visibility internal
  10. %output=Parser.cs
  11. %token csKeyword csIdent csNumber csLitstr csLitchr csOp
  12. csBar "|", csDot ".", semi ";", csStar "*", csLT "<", csGT ">",
  13. comma ",", csSlash "/", csLBrac "[", csRBrac "]", csLPar "(",
  14. csRPar ")", csLBrace "{", csRBrace "}"
  15. %token verbatim pattern name lCond "<", rCond ">",
  16. lxLBrace "{", lxRBrace "}", lxBar "|", defCommentS "/*",
  17. defCommentE "/*...*/", csCommentS "/*", csCommentE "/*...*/"
  18. %token usingTag "%using", namespaceTag "%namespace", optionTag "%option",
  19. charSetPredTag "%charClassPredicate", inclTag "%s", exclTag "%x",
  20. lPcBrace "%{", rPcBrace "%}", visibilityTag "%visibility", PCPC "%%",
  21. userCharPredTag "userCharPredicate", scanbaseTag "%scanbasetype",
  22. tokentypeTag "%tokentype", scannertypeTag "scannertype",
  23. lxIndent lxEndIndent
  24. %token maxParseToken EOL csCommentL errTok repErr
  25. %%
  26. Program
  27. : DefinitionSection Rules
  28. | DefinitionSection RulesSection UserCodeSection
  29. ;
  30. DefinitionSection
  31. : DefinitionSeq PCPC {
  32. isBar = false;
  33. typedeclOK = false;
  34. if (aast.nameString == null)
  35. handler.ListError(@2, 73);
  36. }
  37. | PCPC { isBar = false; }
  38. | error PCPC { handler.ListError(@1, 62, "%%"); }
  39. ;
  40. RulesSection
  41. : Rules PCPC { typedeclOK = true; }
  42. ;
  43. UserCodeSection
  44. : CSharp { aast.UserCode = @1; }
  45. | /* empty */ { /* empty */ }
  46. | error { handler.ListError(@1, 62, "EOF"); }
  47. ;
  48. DefinitionSeq
  49. : DefinitionSeq Definition
  50. | Definition
  51. ;
  52. Definition
  53. : name verbatim { AddLexCategory(@1, @2); }
  54. | name pattern { AddLexCategory(@1, @2); }
  55. | exclTag NameList { AddNames(true); }
  56. | inclTag NameList { AddNames(false); }
  57. | usingTag DottedName semi { aast.usingStrs.Add(@2.Merge(@3)); }
  58. | namespaceTag DottedName { aast.nameString = @2; }
  59. | visibilityTag csKeyword { aast.AddVisibility(@2); }
  60. | optionTag verbatim { ParseOption(@2); }
  61. | PcBraceSection { aast.AddCodeSpan(Dest,@1); }
  62. | DefComment { aast.AddCodeSpan(Dest,@1); }
  63. | IndentedCode { aast.AddCodeSpan(Dest,@1); }
  64. | charSetPredTag NameList { AddCharSetPredicates(); }
  65. | scanbaseTag csIdent { aast.SetScanBaseName(@2.ToString()); }
  66. | tokentypeTag csIdent { aast.SetTokenTypeName(@2.ToString()); }
  67. | scannertypeTag csIdent { aast.SetScannerTypeName(@2.ToString()); }
  68. | userCharPredTag csIdent csLBrac DottedName csRBrac DottedName {
  69. aast.AddUserPredicate(@2.ToString(), @4, @6);
  70. }
  71. ;
  72. IndentedCode
  73. : lxIndent CSharp lxEndIndent { @$ = @2; }
  74. | lxIndent error lxEndIndent { handler.ListError(@2, 64); }
  75. ;
  76. NameList
  77. : NameSeq
  78. | error { handler.ListError(@1, 67); }
  79. ;
  80. NameSeq
  81. : NameSeq comma name { AddName(@3); }
  82. | name { AddName(@1); }
  83. | csNumber { AddName(@1); }
  84. | NameSeq comma error { handler.ListError(@2, 67); }
  85. ;
  86. PcBraceSection
  87. : lPcBrace rPcBrace { @$ = BlankSpan; /* skip blank lines */ }
  88. | lPcBrace CSharpN rPcBrace {
  89. @$ = @2;
  90. }
  91. | lPcBrace error rPcBrace { handler.ListError(@2, 62, "%}"); }
  92. | lPcBrace error PCPC { handler.ListError(@2, 62, "%%"); }
  93. ;
  94. DefComment
  95. : DefComStart CommentEnd
  96. | defCommentE
  97. ;
  98. CommentEnd
  99. : defCommentE
  100. | csCommentE
  101. ;
  102. DefComStart
  103. : DefComStart defCommentS
  104. | DefComStart csCommentS
  105. | defCommentS
  106. ;
  107. BlockComment
  108. : CsComStart CommentEnd
  109. ;
  110. CsComStart
  111. : CsComStart csCommentS
  112. | CsComStart defCommentS
  113. | csCommentS
  114. ;
  115. Rules
  116. : RuleList {
  117. rb.FinalizeCode(aast);
  118. aast.FixupBarActions();
  119. }
  120. | /* empty */
  121. ;
  122. RuleList
  123. : RuleList Rule
  124. | Rule
  125. ;
  126. Rule
  127. : Production
  128. | ProductionGroup { scope.ClearScope(); /* for error recovery */ }
  129. | PcBraceSection { rb.AddSpan(@1); }
  130. | IndentedCode { rb.AddSpan(@1); }
  131. | BlockComment { /* ignore */ }
  132. | csCommentE { /* ignore */ }
  133. ;
  134. Production
  135. : ARule {
  136. int thisLine = @1.startLine;
  137. rb.LLine = thisLine;
  138. if (rb.FLine == 0) rb.FLine = thisLine;
  139. }
  140. ;
  141. ProductionGroup
  142. : StartCondition lxLBrace PatActionList lxRBrace {
  143. scope.ExitScope();
  144. }
  145. ;
  146. PatActionList
  147. : /* empty */ {
  148. int thisLine = @$.startLine;
  149. rb.LLine = thisLine;
  150. if (rb.FLine == 0)
  151. rb.FLine = thisLine;
  152. }
  153. | PatActionList ARule
  154. | PatActionList ProductionGroup
  155. ;
  156. ARule
  157. : StartCondition pattern Action {
  158. RuleDesc rule = new RuleDesc(@2, @3, scope.Current, isBar);
  159. aast.ruleList.Add(rule);
  160. rule.ParseRE(aast);
  161. isBar = false; // Reset the flag ...
  162. scope.ExitScope();
  163. }
  164. | pattern Action {
  165. RuleDesc rule = new RuleDesc(@1, @2, scope.Current, isBar);
  166. aast.ruleList.Add(rule);
  167. rule.ParseRE(aast);
  168. isBar = false; // Reset the flag ...
  169. }
  170. | error { handler.ListError(@1, 68); scope.ClearScope(); }
  171. ;
  172. StartCondition
  173. : lCond NameList rCond {
  174. List<StartState> list = new List<StartState>();
  175. AddNameListToStateList(list);
  176. scope.EnterScope(list);
  177. }
  178. | lCond csStar rCond {
  179. List<StartState> list = new List<StartState>();
  180. list.Add(StartState.allState);
  181. scope.EnterScope(list);
  182. }
  183. ;
  184. CSharp
  185. : CSharpN
  186. ;
  187. CSharpN
  188. : NonPairedToken
  189. | CSharpN NonPairedToken
  190. | CSharpN WFCSharpN
  191. | WFCSharpN
  192. ;
  193. WFCSharpN
  194. /* : NonPairedToken */
  195. : csLBrace csRBrace
  196. | csLBrace CSharpN csRBrace
  197. | csLPar csRPar
  198. | csLPar CSharpN csRPar
  199. | csLBrac csRBrac
  200. | csLBrac CSharpN csRBrac
  201. | csLPar error { handler.ListError(@2, 61, "')'"); }
  202. | csLBrac error { handler.ListError(@2, 61, "']'"); }
  203. | csLBrace error { handler.ListError(@2, 61, "'}'"); }
  204. ;
  205. DottedName
  206. : csIdent { /* skip1 */ }
  207. | csKeyword csDot csIdent { /* skip2 */ }
  208. | DottedName csDot csIdent { /* skip3 */ }
  209. ;
  210. NonPairedToken
  211. : BlockComment
  212. | DottedName
  213. | csCommentE
  214. | csCommentL
  215. | csKeyword {
  216. string text = aast.scanner.yytext;
  217. if (text.Equals("using")) {
  218. handler.ListError(@1, 56);
  219. } else if (text.Equals("namespace")) {
  220. handler.ListError(@1, 57);
  221. } else {
  222. if ((text.Equals("class") || text.Equals("struct") ||
  223. text.Equals("enum")) && !typedeclOK) handler.ListError(@1,58);
  224. }
  225. }
  226. | csNumber
  227. | csLitstr
  228. | csLitchr
  229. | csOp
  230. | csDot
  231. | csStar
  232. | csLT
  233. | csGT
  234. | semi
  235. | comma
  236. | csSlash
  237. | csBar
  238. ;
  239. Action
  240. : lxLBrace CSharp lxRBrace { @$ = @2; }
  241. | CSharp
  242. | lxBar { isBar = true; }
  243. | lxLBrace lxRBrace
  244. | lxLBrace error lxRBrace { handler.ListError(@$, 65); }
  245. | error { handler.ListError(@1, 63); }
  246. ;
  247. %%