meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
up_to_here [2020/09/26 17:07] – [Niggles (Annoying Details)] revuskyup_to_here [2023/03/03 14:26] (current) revusky
Line 1: Line 1:
-===== The "Up-to-here" Construct =====+===== The "Up-to-here" Marker =====
  
-The //up-to-here// marker ''=>||'' and the //up-to-here-plus// marker ''=>|+n'' (where n is an integer) was introduced to be able to express [[lookahead]] in a more succinct and less err-prone manner than using the legacy ''LOOKAHEAD'' or even the terser ''SCAN'' statement.+The //up-to-here// marker ''=>||'' and the //up-to-here-plus// marker ''=>|+n'' (where n is an integer) were introduced to be able to express [[lookahead]] in a more succinct and less err-prone manner than using the ''LOOKAHEAD'' from legacy JavaCC or even the terser ''SCAN'' statement.
  
 Where in legacy JavaCC, you would write: Where in legacy JavaCC, you would write:
Line 9: Line 9:
 </code>     </code>    
  
-or in JavaCC 21 (//without up-to-here//) you could write:+or in CongoCC (//without up-to-here//) you could write:
  
 <code> <code>
Line 45: Line 45:
 </code> </code>
  
-(I refer to these as //simple// because both of them are just a sequence of three string literal tokens. The same concept applies to much more complex expansions, of course.)+(I refer to these as //simple// because both of them are just a sequence of three string literal tokens. I use these as examples, but the same concept applies to much more complex expansions, of course.)
  
 Suppose further that we have a choice construct: Suppose further that we have a choice construct:
Line 53: Line 53:
 </code> </code>
  
-Now, if no ''LOOKAHEAD'' (or ''SCAN'') is specified, then the ''Foobaz'' production is going to be unreachable. This is because, by default, JavaCC looks ahead exactly one token to decide which of the two expansions to enter, and will simply go with the first one that matches. So, assuming that the next token is a "foo", then it will //always// enter ''Foobar'' and ''Foobaz'' is unreachable.+Now, if no ''LOOKAHEAD'' (or ''SCAN'') is specified, then the ''Foobaz'' production is going to be unreachable. This is because, by default, CongoCC looks ahead exactly one token to decide which of the two expansions to enter, and will simply go with the first one that matches. So, assuming that the next token is a "foo", then it will //always// enter ''Foobar'' and the second choice, ''Foobaz''is unreachable.
  
 The classic solution would be to specify two tokens of lookahead, so that we need to match "foo" followed by "bar" to enter ''Foobar''. Like so: The classic solution would be to specify two tokens of lookahead, so that we need to match "foo" followed by "bar" to enter ''Foobar''. Like so:
Line 61: Line 61:
 </code> </code>
  
-In JavaCC 21, you have the option of putting an //up-to-here// marker in the ''Foobar'' production like so:+In CongoCC, you have the option of putting an //up-to-here// marker in the ''Foobar'' production like so:
  
 <code> <code>
Line 67: Line 67:
 </code> </code>
  
-This means that we scan up to (and including) the "bar" token when the expansion at a [[choice point]] starts with ''Foobar''.+This means that we scan up to (and including) the "bar" token when the expansion at a [[choice points|choice point]] starts with ''Foobar''.
  
 Now, the choice construct above can be written simply as: Now, the choice construct above can be written simply as: