Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

What is currentFunc, though? Normally that is a parser class instance variable set to the currently matched function by an action in the parser grammar. For constructs that can nest such as classes in some languages, the "current class" pointer needs to be treated like a stack. ANTLR has dynamically scoped very rules for this purpose; perhaps we could do something similar.

No Format

method:
  scope { FunctionSymbol currentFunc; }
  blah blah blah

The result of a pattern match could be an action or perhaps even just a context with no pattern:

No Format
method:
  {System.out.println("heh, I just entered a method")} // always exec in method context
  type ID {currentFunc = currentScope.resolve($ID.text);} // exec this but referredrefer to ID

We might also need to be able to specify a predicate on token references:

No Format

expr:
  ID<"null"> -> "nil" // test for null keyword as ID
  ^('*' INT<{is power of 2}> expr) -> (lg2={$INT.int}) "<expr> << <lg2>"

Rewrites for tree grammars

There is no reason we could not do rewrite patterns on trees. The left would always be a tree pattern but the right could be a tree pattern or template.

No Format

expr:
  ^('+' expr expr) -> add(blah blah blah) // rewrite with template ref
  INT -> "0" // differentiate any integer to constant "0"

To rewrite to another tree:

No Format

expr:
  ^('+' INT<"0"> expr) -> expr
  ^('*' INT<"1"> expr) -> expr