Skip to content

Instantly share code, notes, and snippets.

%{
int nchar, nword, nline;
%}
%%
\n { nline++; nchar++; }
[^ \t\n]+ { nword++, nchar += yyleng; }
. { nchar++; }
%%
grammar Expr;
@header {
package test;
import java.util.HashMap;
}
@lexer::header {package test;}
@members {
grammar ExprAst;
options {
output=AST;
ASTLabelType=CommonTree; // type of $stat.tree ref etc...
}
prog: ( stat {System.out.println($stat.tree.toStringTree());} )+ ;
stat: expr NEWLINE -> expr
| ID '=' expr NEWLINE -> ^('=' ID expr)
public class AddCharDemo
{
public static void main(String []args) {
int i = 3;
int j = 5;
System.out.println(i + ' ' + j);
System.out.println(' ' + 0);
}
}
public class IncDemo
{
public static void main(String []args) {
int i = 2;
i = i++;
System.out.println("int i = 2; i = i++ equals: " + i);
}
}
-- hex dump
-- usage: lua xd.lua < file
local offset=0
while true do
local s=io.read(16)
if s==nil then return end
io.write(string.format("%08X ",offset))
string.gsub(s,"(.)",
function (c) io.write(string.format("%02X ",string.byte(c))) end)
use strict;
use warnings;
use Purple;
our %PLUGIN_INFO = (
perl_api_version => 2,
name => "Fortune Plugin",
version => "0.1",
summary => "Fortune plugin.",
description => "Set fortune output as status when plugin load.",
#! /usr/bin/guile -s
!#
(let* ((yin ((lambda (foo) (newline) foo)
(call-with-current-continuation (lambda (bar) bar))))
(yang ((lambda (foo) (write-char #\*) foo)
(call-with-current-continuation (lambda (bar) bar)))))
(yin yang))
from twisted.words.xish import domish
from wokkel.xmppim import MessageProtocol, AvailablePresence
class EchoBotProtocol(MessageProtocol):
def __init__(self, component=False):
MessageProtocol.__init__(self)
self.component = component
-module(countdown).
-export([countdown/1]).
countdown(0) -> io:format("Blast Off!~n");
countdown(X) -> io:format("~w~n", [X]), countdown(X-1).