lexical

Why does Programming Perl use local (not my) for filehandles?

When I read through Programming Perl, 2nd Edition, Page 51, something confuses me : sub newopen { my $path = shift; local *FH; #not my! open (FH, $path) || return undef; return *FH; } $fh = newopen('/etc/passwd'); My I know, why we are not recommenced to use my? So far, I cannot see anything will go wrong if we use...

Need abbreviation translation database

Is there such a thing? I'm looking to translate something like "mfg"=>"manufacturing" or . I figure that I'd need a database of mappings. However, I can't seem to find one. I'm don't know a lot about lexical translations and the budget doesn't call for a lot of research, so are there any quick 'n dirty tools out there? ...

When should you use a package variable vs a lexical variable (and what's the difference)?

I'm looking at some older Perl code on Perl Monks to figure out programming with Win32::OLE and MS Word. Scattered throughout the code are variables with names like $MS::Word and the like, without a 'my' included in their declaration. After reading a bit on Google, I understand that these are called 'package variables' versus 'lexical va...

Problems with pointers when building a Pascal compiler in C

Hello guys I'm facing some problems on the lexical analysis of my compiler I had declared the following pointer char *words[29]={ "program", "label", "integer", "word", "char", "byte", "shortint", "logint", "real", "single", "double", "string", "boolean", "var", ...

Insert text in the input file in Lex (with C)

Hey! I'm trying to help a friend in a college assignment, but i kind of forgot a lot of C an Lex. The thing is, we are trying to parse a HTML and a correspondent CSS file and add to a tag it's style. Eg: HTML <body> </body> CSS body{color:black;} modified HTML <body style="color:black;"> </body> All the regex are done and ...

Can lexical analyzer stage check grammar rules during compilation?

Hi guys, sorry for such silly question, but I had argument with my pals about lexical analyze and we've decided to ask community. The question is: Whether the statement "int some_variable = ;" would be interpreted as invalid during the lexical analyze stage or during the syntax analyze stage in C grammar. Thanks ...

Why can't I use a Perl variable's value to access a lexical variable name?

Why does this print 42: $answer = 42; $variable = "answer"; print ${$variable} . "\n"; but this doesn't: my $answer = 42; my $variable = "answer"; print ${$variable} . "\n"; ...

Xs:pattern interpretation in XML

How to interpret the following xml element? xs:pattern value="[ !-~]*" ...

PHP - Words in a db - search via lexical dictionary (semantic similarity)

I'm implementing a small dictionary database where I'd like to do searches based on lexical/semantic similarity between them.. For example, beer has "sister words" such as soda, lemonade, wine, champagne each "different" in a "different direction" (in example: the first two are "moderate" versions of the idea of "beer", while the latte...

The good, the bad, and the ugly of lexical $_ in Perl 5.10+

Starting in Perl 5.10, it is now possible to lexically scope the context variable $_, either explicitly as my $_; or in a given / when construct. Has anyone found good uses of the lexical $_? Does it make any constructs simpler / safer / faster? What about situations that it makes more complicated? Has the lexical $_ introduced any b...

How to combine Regexp and keywords in Scala parser combinators

I've seen two approaches to building parsers in Scala. The first is to extends from RegexParsers and define your won lexical patterns. The issue I see with this is that I don't really understand how it deals with keyword ambiguities. For example, if my keyword match the same pattern as idents, then it processes the keywords as idents....